using System;
using System.Collections;
using System.Collections.Specialized;
using System.Data;
using System.Data.SqlTypes;
using System.Data.SqlClient;
using System.Text;
using System.Collections.Generic;
using eShop.Utility;


namespace Entity
{
	/// <summary>
	/// This object represents the Private Fields of TblSettings.
	/// </summary>
	
	[System.ComponentModel.DataObject]
    public class TblSettings : DatabaseUtility
    {
		#region TblSettings Private Fields


		Int32 _settingsId;
		String _companyName = String.Empty;
		String _companyAddress = String.Empty;
		String _companyZip = String.Empty;
		String _companyCity = String.Empty;
		String _companyState = String.Empty;
		String _companyCountry = String.Empty;
		String _companyPhone = String.Empty;
		String _companyEmail = String.Empty;
		String _companyFax = String.Empty;
		String _customerPrefix = String.Empty;
		String _orederPrefix = String.Empty;
		String _adminEmail = String.Empty;
		Int32 _stockAlertLevel;
		Decimal _minimumOrder;
		Boolean _isGroundShippingFree;
		Decimal _groundShippingAmount;
		String _homePageBannerImage = String.Empty;
		String _homePageFooterImage = String.Empty;
		String _homePageVideoImage = String.Empty;
		String _footerImageAnchorUrl = String.Empty;
		
		#endregion
		#region TblSettings Constractor
		/// <summary>
        /// Creates an empty object of TblSettings. 
        /// This is mainly used to create a new instance of TblSettings to add a new TblSettings.
        /// </summary>
		public TblSettings(){}
		
				
		/// <summary>
        /// Used to retrieve employee information from database, 
        /// which is also used by Update method to save information of an existing TblSettings.
        /// </summary>
		public TblSettings
		(
			Int32 settingsId,
			String companyName,
			String companyAddress,
			String companyZip,
			String companyCity,
			String companyState,
			String companyCountry,
			String companyPhone,
			String companyEmail,
			String companyFax,
			String customerPrefix,
			String orederPrefix,
			String adminEmail,
			Int32 stockAlertLevel,
			Decimal minimumOrder,
			Boolean isGroundShippingFree,
			Decimal groundShippingAmount,
			String homePageBannerImage,
			String homePageFooterImage,
			String homePageVideoImage,
			String footerImageAnchorUrl
		)
		{
			_settingsId = settingsId;	
			_companyName = companyName;	
			_companyAddress = companyAddress;	
			_companyZip = companyZip;	
			_companyCity = companyCity;	
			_companyState = companyState;	
			_companyCountry = companyCountry;	
			_companyPhone = companyPhone;	
			_companyEmail = companyEmail;	
			_companyFax = companyFax;	
			_customerPrefix = customerPrefix;	
			_orederPrefix = orederPrefix;	
			_adminEmail = adminEmail;	
			_stockAlertLevel = stockAlertLevel;	
			_minimumOrder = minimumOrder;	
			_isGroundShippingFree = isGroundShippingFree;	
			_groundShippingAmount = groundShippingAmount;	
			_homePageBannerImage = homePageBannerImage;	
			_homePageFooterImage = homePageFooterImage;	
			_homePageVideoImage = homePageVideoImage;	
			_footerImageAnchorUrl = footerImageAnchorUrl;	
		}
		
		#endregion
		#region TblSettings Properties
		
		 /***********************************************************************************************
                                    -- PROPERTIES --        
         Contains all the properties representing the data fields of the current entity.
         ***********************************************************************************************/

        /// <summary>
        /// This is the Primary key value of the SettingsId, which can't be assigned from the application,
        /// to ensure the data consistancy, by not letting the user to change the PK_TblSettings to update the data of an another TblSettings instance.
        /// For view or updation purpose, every TblSettings will be retrieved thru the proper 'Get' method.
        /// </summary>
		
		public Int32 SettingsId
		{
			get {return _settingsId;}	
		}
		
				
		public String CompanyName
		{
			get {return _companyName;}
			set {_companyName = value;}
		}

		public String CompanyAddress
		{
			get {return _companyAddress;}
			set {_companyAddress = value;}
		}

		public String CompanyZip
		{
			get {return _companyZip;}
			set {_companyZip = value;}
		}

		public String CompanyCity
		{
			get {return _companyCity;}
			set {_companyCity = value;}
		}

		public String CompanyState
		{
			get {return _companyState;}
			set {_companyState = value;}
		}

		public String CompanyCountry
		{
			get {return _companyCountry;}
			set {_companyCountry = value;}
		}

		public String CompanyPhone
		{
			get {return _companyPhone;}
			set {_companyPhone = value;}
		}

		public String CompanyEmail
		{
			get {return _companyEmail;}
			set {_companyEmail = value;}
		}

		public String CompanyFax
		{
			get {return _companyFax;}
			set {_companyFax = value;}
		}

		public String CustomerPrefix
		{
			get {return _customerPrefix;}
			set {_customerPrefix = value;}
		}

		public String OrederPrefix
		{
			get {return _orederPrefix;}
			set {_orederPrefix = value;}
		}

		public String AdminEmail
		{
			get {return _adminEmail;}
			set {_adminEmail = value;}
		}

		public Int32 StockAlertLevel
		{
			get {return _stockAlertLevel;}
			set {_stockAlertLevel = value;}
		}

		public Decimal MinimumOrder
		{
			get {return _minimumOrder;}
			set {_minimumOrder = value;}
		}

		public Boolean IsGroundShippingFree
		{
			get {return _isGroundShippingFree;}
			set {_isGroundShippingFree = value;}
		}

		public Decimal GroundShippingAmount
		{
			get {return _groundShippingAmount;}
			set {_groundShippingAmount = value;}
		}

		public String HomePageBannerImage
		{
			get {return _homePageBannerImage;}
			set {_homePageBannerImage = value;}
		}

		public String HomePageFooterImage
		{
			get {return _homePageFooterImage;}
			set {_homePageFooterImage = value;}
		}

		public String HomePageVideoImage
		{
			get {return _homePageVideoImage;}
			set {_homePageVideoImage = value;}
		}

		public String FooterImageAnchorUrl
		{
			get {return _footerImageAnchorUrl;}
			set {_footerImageAnchorUrl = value;}
		}
		

		#endregion
		#region TblSettings Static Methods
		/************************************************************************************
                                    -- CREATE METHOD (STATIC) --
        *************************************************************************************/
		/************************* Architecure note:**********************************
        Note 1:
        This method is specially useful for the case, where we need to use Object Data Source controls.
        For ObjectDataSource/SqlDataSource controls, the insert/update metnod requires paramters methods, rather property based methods.
        However, there is still a way to pass property based objects as method parameter for data source controls, 
        but in that case we could not use Sql type, as view controls or asp parameter control can only contain few of primitive type.
        The main reason to remain the Sql Type in our object architecture is it is faster and contains better way for null value support.
        
        Note 2: 
        Non-primary key: it should be primitive type, as the asp paramter control (included in data source control) supports only primitive types.
        /*****************************************************************************/
		[System.ComponentModel.DataObjectMethodAttribute(System.ComponentModel.DataObjectMethodType.Insert, true)]
        public static  Int32 CreateNewTblSettings
		(
			String companyName,
			String companyAddress,
			String companyZip,
			String companyCity,
			String companyState,
			String companyCountry,
			String companyPhone,
			String companyEmail,
			String companyFax,
			String customerPrefix,
			String orederPrefix,
			String adminEmail,
			Int32 stockAlertLevel,
			Decimal minimumOrder,
			Boolean isGroundShippingFree,
			Decimal groundShippingAmount,
			String homePageBannerImage,
			String homePageFooterImage,
			String homePageVideoImage,
			String footerImageAnchorUrl
		)
		{
			//creating an empty TblSettings object
            TblSettings tblSettings = new TblSettings();
				tblSettings.CompanyName = companyName;
				tblSettings.CompanyAddress = companyAddress;
				tblSettings.CompanyZip = companyZip;
				tblSettings.CompanyCity = companyCity;
				tblSettings.CompanyState = companyState;
				tblSettings.CompanyCountry = companyCountry;
				tblSettings.CompanyPhone = companyPhone;
				tblSettings.CompanyEmail = companyEmail;
				tblSettings.CompanyFax = companyFax;
				tblSettings.CustomerPrefix = customerPrefix;
				tblSettings.OrederPrefix = orederPrefix;
				tblSettings.AdminEmail = adminEmail;
				tblSettings.StockAlertLevel = stockAlertLevel;
				tblSettings.MinimumOrder = minimumOrder;
				tblSettings.IsGroundShippingFree = isGroundShippingFree;
				tblSettings.GroundShippingAmount = groundShippingAmount;
				tblSettings.HomePageBannerImage = homePageBannerImage;
				tblSettings.HomePageFooterImage = homePageFooterImage;
				tblSettings.HomePageVideoImage = homePageVideoImage;
				tblSettings.FooterImageAnchorUrl = footerImageAnchorUrl;
			
			return TblSettings.CreateNewTblSettings(tblSettings);
		}
	
		/************************************************************************************
                 -- UPDATE METHODS (STATIC) --
        *************************************************************************************/

        /************************* Architecure note:**********************************
        Note 1:
        This method is specially useful for the case, where we need to use Object Data Source controls.
        For ObjectDataSource/SqlDataSource controls, the insert/update metnod requires paramters methods, rather property based methods.
        However, there is still a way to pass property based objects as method parameter for data source controls, 
        but in that case we could not use Sql type, as view controls or asp parameter control can only contain few of primitive type.
        The main reason to remain the Sql Type in our object architecture is it is faster and contains better way for null value support.
        
        Note 2: 
        There the two types of paramaters will be passed here.
         * a. Primary key paramater: it should be Sql type, as we will bind the primary key property for the view controls (form view, details view etc) as datakey.
         * b. Non-primary key: it should be primitive type, as the asp paramter control (included in data source control) supports only primitive types.
        /*****************************************************************************/
		
		[System.ComponentModel.DataObjectMethodAttribute(System.ComponentModel.DataObjectMethodType.Update, true)]
        public static  bool UpdateTblSettings
		(
			Int32 settingsId,
			String companyName,
			String companyAddress,
			String companyZip,
			String companyCity,
			String companyState,
			String companyCountry,
			String companyPhone,
			String companyEmail,
			String companyFax,
			String customerPrefix,
			String orederPrefix,
			String adminEmail,
			Int32 stockAlertLevel,
			Decimal minimumOrder,
			Boolean isGroundShippingFree,
			Decimal groundShippingAmount,
			String homePageBannerImage,
			String homePageFooterImage,
			String homePageVideoImage,
			String footerImageAnchorUrl
		)
		{
			 TblSettings tblSettings =  TblSettings.GetTblSettingsBySettingsId(settingsId);
			
				tblSettings.CompanyName = companyName;
				tblSettings.CompanyAddress = companyAddress;
				tblSettings.CompanyZip = companyZip;
				tblSettings.CompanyCity = companyCity;
				tblSettings.CompanyState = companyState;
				tblSettings.CompanyCountry = companyCountry;
				tblSettings.CompanyPhone = companyPhone;
				tblSettings.CompanyEmail = companyEmail;
				tblSettings.CompanyFax = companyFax;
				tblSettings.CustomerPrefix = customerPrefix;
				tblSettings.OrederPrefix = orederPrefix;
				tblSettings.AdminEmail = adminEmail;
				tblSettings.StockAlertLevel = stockAlertLevel;
				tblSettings.MinimumOrder = minimumOrder;
				tblSettings.IsGroundShippingFree = isGroundShippingFree;
				tblSettings.GroundShippingAmount = groundShippingAmount;
				tblSettings.HomePageBannerImage = homePageBannerImage;
				tblSettings.HomePageFooterImage = homePageFooterImage;
				tblSettings.HomePageVideoImage = homePageVideoImage;
				tblSettings.FooterImageAnchorUrl = footerImageAnchorUrl;
			
			return TblSettings.UpdateTblSettings(tblSettings);
		}

		/************************************************************************************
                         -- DELETE METHODS --
        *************************************************************************************/
        /************************* Architecure note:**********************************
        We have used the employeeId parameter as SqlInt32, to bind the delete method with object data source and view control directly.
        ****************************************************************************/
		[System.ComponentModel.DataObjectMethodAttribute(System.ComponentModel.DataObjectMethodType.Update, true)]
        public static  bool DeleteTblSettings
		(
			Int32 settingsId
		)
		{
			//Validate Input
			if(settingsId <= GetSettingsIdMinValue)
				throw (new ArgumentOutOfRangeException("settingsId"));
				
			// Execute SQL Command
            SqlCommand sqlCmd = new SqlCommand();
			AddParameterToSqlCmd(sqlCmd, "@ReturnValue", SqlDbType.Int, 0, ParameterDirection.ReturnValue, null);
			AddParameterToSqlCmd(sqlCmd, "@SettingsId",SqlDbType.Int, 0, ParameterDirection.Input, settingsId);
			SetCommandType(sqlCmd,CommandType.StoredProcedure,SPR_TBLSETTINGS_DELETETBLSETTINGS);
			ExecuteScalarCmd(sqlCmd);
			int returnValue = (int)sqlCmd.Parameters["@ReturnValue"].Value;
			return (returnValue == 0 ? false : true);
			
		}
		
		/// <summary>
        /// Deletes a set of employees from the database.
        /// </summary>
		public static bool DeleteTblSettingsList( System.Collections.Generic.List<Int32>  settingsIdListToDelete)
		{
			//Validate Input
			foreach (Int32 settingsId in settingsIdListToDelete)
			    if(settingsId <= GetSettingsIdMinValue)
					throw (new ArgumentOutOfRangeException("settingsId"));
			
			//performing deletion operation //

            string xmlString = FormatXMLForIdArray(settingsIdListToDelete);
			
			// Execute SQL Command
            SqlCommand sqlCmd = new SqlCommand();
			AddParameterToSqlCmd(sqlCmd, "@ReturnValue", SqlDbType.Int, 0, ParameterDirection.ReturnValue, null);
            AddParameterToSqlCmd(sqlCmd, "@SettingsIdList", SqlDbType.Xml, xmlString.ToString().Length, ParameterDirection.Input, xmlString.ToString());
			SetCommandType(sqlCmd,CommandType.StoredProcedure,SPR_TBLSETTINGS_DELETETBLSETTINGSLIST);
			ExecuteScalarCmd(sqlCmd);
			int returnValue = (int)sqlCmd.Parameters["@ReturnValue"].Value;
			return (returnValue == settingsIdListToDelete.Count ? true : false);
		}
		
		/************************************************************************************
                                 -- GET BY PRIMARY METHODS --
        *************************************************************************************/
        /************************* Architecure note:**********************************
        Retrives an Employee from database, based on it's primary key.
        To view or update an employee, everytime we must have to use this type of 'get' method, 
        since we don't have direct access to the Primary key value for assigning value.
        We have used the employeeId parameter as SqlInt32, to bind the delete method with object data source and view control directly.
        /*****************************************************************************/
		[System.ComponentModel.DataObjectMethodAttribute(System.ComponentModel.DataObjectMethodType.Select, true)]
		public static TblSettings GetTblSettingsBySettingsId(Int32 settingsId)
		{
			if(settingsId <= GetSettingsIdMinValue)
					throw (new ArgumentOutOfRangeException("settingsId"));
				
		 	// Execute SQL Command
			SqlCommand sqlCmd = new SqlCommand();
			AddParameterToSqlCmd(sqlCmd, "@SettingsId",SqlDbType.Int, 0, ParameterDirection.Input, settingsId);
			SetCommandType(sqlCmd,CommandType.StoredProcedure,SPR_TBLSETTINGS_GETTBLSETTINGSBYSETTINGSID);
			GenerateCollectionFromReader test = new GenerateCollectionFromReader(GenerateTblSettingsCollectionFromReader);
            List<TblSettings> objCollection = ((List<TblSettings>)ExecuteReaderCmd(sqlCmd, test));

            if (objCollection.Count > 0)
                return objCollection[0];
            else
                return null;
		}
		
		/************************************************************************************
                         -- GET BY FOREIGN KEY METHODS --
        *************************************************************************************/
		
		/************************************************************************************
                 -- GET ALL METHODS --
        *************************************************************************************/
		[System.ComponentModel.DataObjectMethodAttribute(System.ComponentModel.DataObjectMethodType.Select, true)]
        public static List<TblSettings> GetAllTblSettings()
		{
		
		 	// Execute SQL Command
            SqlCommand sqlCmd = new SqlCommand();
            SetCommandType(sqlCmd,CommandType.StoredProcedure,SPR_TBLSETTINGS_GETALLTBLSETTINGS);
            GenerateCollectionFromReader test = new GenerateCollectionFromReader(GenerateTblSettingsCollectionFromReader);
            List<TblSettings> objCollection = ((List<TblSettings>)ExecuteReaderCmd(sqlCmd, test));

            return objCollection;
		}
		
		[System.ComponentModel.DataObjectMethodAttribute(System.ComponentModel.DataObjectMethodType.Select, true)]
        public static List<TblSettings> GetAllTblSettingsPaged(String orderBy, Int32 startRowIndex, Int32 maximumRows)
        {
            //Validate Input
            if (orderBy == "")
                orderBy = "SettingsId";

            // Execute SQL Command
            SqlCommand sqlCmd = new SqlCommand();
            AddParameterToSqlCmd(sqlCmd, "@orderby", SqlDbType.VarChar, 50, ParameterDirection.Input, orderBy);
            AddParameterToSqlCmd(sqlCmd, "@startrow", SqlDbType.Int, 0, ParameterDirection.Input, startRowIndex);
            AddParameterToSqlCmd(sqlCmd, "@pagesize", SqlDbType.Int, 0, ParameterDirection.Input, maximumRows);

            SetCommandType(sqlCmd,CommandType.StoredProcedure,SPR_TBLSETTINGS_GETALLTBLSETTINGSPAGED);

            GenerateCollectionFromReader test = new GenerateCollectionFromReader(GenerateTblSettingsCollectionFromReader);
            List<TblSettings> objCollection = ((List<TblSettings>)ExecuteReaderCmd(sqlCmd, test));
            return objCollection;
        }
		
		[System.ComponentModel.DataObjectMethodAttribute(System.ComponentModel.DataObjectMethodType.Select, true)]
        public static int GetAllTblSettingsPagedCount(String orderBy, Int32 startRowIndex, Int32 maximumRows)
        {
            // Execute SQL Command
            SqlCommand sqlCmd = new SqlCommand();

            AddParameterToSqlCmd(sqlCmd, "@ReturnValue", SqlDbType.Int, 0, ParameterDirection.ReturnValue, null);
            SetCommandType(sqlCmd,CommandType.StoredProcedure,SPR_TBLSETTINGS_GETALLTBLSETTINGSPAGEDCOUNT);
            ExecuteScalarCmd(sqlCmd);

            int returnValue = (int)sqlCmd.Parameters["@ReturnValue"].Value;
            return returnValue;
        }
		
		#endregion
		#region Employee Instance Methods
		/************************************************************************************
                                    -- SAVE (INSERT/UPDATE) METHODS (INSTANCE) --
        *************************************************************************************/
		/// <summary>
        /// Saves (inserts and updates) an Employee into database.
        /// The insertion occur if the EmployeeId conatins default value.
        /// Otherwises it updates the Employee into the database, based on the primary key value stored in EmployeeId.
        /// This technique ensures an Employee will not be updated without having a valid EmployeeId.
        /// </summary>
		public bool Save()
		{
			if(SettingsId<= GetSettingsIdMinValue)
			{
				Int32 TempId=CreateNewTblSettings(this);
				if(TempId>0)
				{
					_settingsId=TempId;
					return true;
				}
				else
				{
					// error occurs
					return false;
				}
			}
			else
			{	//This is a update Command
				return (UpdateTblSettings(this));
			}
			
		}
		
		public static Int32 CreateNewTblSettings(TblSettings newTblSettings)
		{
			// validate Parameters
			if (newTblSettings == null)
				throw (new ArgumentNullException("newTblSettings"));

			// Execute SQL Command
			SqlCommand sqlCmd = new SqlCommand();
			int length = 0;
			AddParameterToSqlCmd(sqlCmd, "@ReturnValue", SqlDbType.Int, 0, ParameterDirection.ReturnValue, null);
            
			AddParameterToSqlCmd(sqlCmd, "@CompanyName",SqlDbType.NVarChar, 500, ParameterDirection.Input, newTblSettings.CompanyName);
			AddParameterToSqlCmd(sqlCmd, "@CompanyAddress",SqlDbType.NVarChar, 4000, ParameterDirection.Input, newTblSettings.CompanyAddress);
			AddParameterToSqlCmd(sqlCmd, "@CompanyZip",SqlDbType.NVarChar, 500, ParameterDirection.Input, newTblSettings.CompanyZip);
			AddParameterToSqlCmd(sqlCmd, "@CompanyCity",SqlDbType.NVarChar, 500, ParameterDirection.Input, newTblSettings.CompanyCity);
			AddParameterToSqlCmd(sqlCmd, "@CompanyState",SqlDbType.NVarChar, 500, ParameterDirection.Input, newTblSettings.CompanyState);
			AddParameterToSqlCmd(sqlCmd, "@CompanyCountry",SqlDbType.NVarChar, 500, ParameterDirection.Input, newTblSettings.CompanyCountry);
			AddParameterToSqlCmd(sqlCmd, "@CompanyPhone",SqlDbType.NVarChar, 500, ParameterDirection.Input, newTblSettings.CompanyPhone);
			AddParameterToSqlCmd(sqlCmd, "@CompanyEmail",SqlDbType.NVarChar, 500, ParameterDirection.Input, newTblSettings.CompanyEmail);
			AddParameterToSqlCmd(sqlCmd, "@CompanyFax",SqlDbType.NVarChar, 500, ParameterDirection.Input, newTblSettings.CompanyFax);
			AddParameterToSqlCmd(sqlCmd, "@CustomerPrefix",SqlDbType.NVarChar, 500, ParameterDirection.Input, newTblSettings.CustomerPrefix);
			AddParameterToSqlCmd(sqlCmd, "@OrederPrefix",SqlDbType.NVarChar, 500, ParameterDirection.Input, newTblSettings.OrederPrefix);
			AddParameterToSqlCmd(sqlCmd, "@AdminEmail",SqlDbType.NVarChar, 500, ParameterDirection.Input, newTblSettings.AdminEmail);
			AddParameterToSqlCmd(sqlCmd, "@StockAlertLevel",SqlDbType.Int, 0, ParameterDirection.Input, newTblSettings.StockAlertLevel);
			AddParameterToSqlCmd(sqlCmd, "@MinimumOrder",SqlDbType.Decimal, 9, ParameterDirection.Input, newTblSettings.MinimumOrder);
			AddParameterToSqlCmd(sqlCmd, "@IsGroundShippingFree",SqlDbType.Bit, 0, ParameterDirection.Input, newTblSettings.IsGroundShippingFree);
			AddParameterToSqlCmd(sqlCmd, "@GroundShippingAmount",SqlDbType.Decimal, 9, ParameterDirection.Input, newTblSettings.GroundShippingAmount);
			AddParameterToSqlCmd(sqlCmd, "@HomePageBannerImage",SqlDbType.NVarChar, -1, ParameterDirection.Input, newTblSettings.HomePageBannerImage);
			AddParameterToSqlCmd(sqlCmd, "@HomePageFooterImage",SqlDbType.NVarChar, -1, ParameterDirection.Input, newTblSettings.HomePageFooterImage);
			AddParameterToSqlCmd(sqlCmd, "@HomePageVideoImage",SqlDbType.NVarChar, -1, ParameterDirection.Input, newTblSettings.HomePageVideoImage);
			AddParameterToSqlCmd(sqlCmd, "@FooterImageAnchorUrl",SqlDbType.NVarChar, -1, ParameterDirection.Input, newTblSettings.FooterImageAnchorUrl);
			
			SetCommandType(sqlCmd,CommandType.StoredProcedure,SPR_TBLSETTINGS_CREATENEWTBLSETTINGS);
			ExecuteScalarCmd(sqlCmd);
			return (Int32.Parse(sqlCmd.Parameters["@ReturnValue"].Value.ToString()));

		}
		/// <summary>
        /// Updates an TblSettings instance to the database.
        /// </summary>
		public static bool UpdateTblSettings(TblSettings newTblSettings)
		{
			// validate Parameters
			if (newTblSettings == null)
				throw (new ArgumentNullException("newTblSettings"));

			// Execute SQL Command
			SqlCommand sqlCmd = new SqlCommand();
			int length = 0;
			AddParameterToSqlCmd(sqlCmd, "@ReturnValue", SqlDbType.Int, 0, ParameterDirection.ReturnValue, null);
            
			AddParameterToSqlCmd(sqlCmd, "@SettingsId",SqlDbType.Int, 0, ParameterDirection.Input, newTblSettings.SettingsId);
			AddParameterToSqlCmd(sqlCmd, "@CompanyName",SqlDbType.NVarChar, 500, ParameterDirection.Input, newTblSettings.CompanyName);
			AddParameterToSqlCmd(sqlCmd, "@CompanyAddress",SqlDbType.NVarChar, 4000, ParameterDirection.Input, newTblSettings.CompanyAddress);
			AddParameterToSqlCmd(sqlCmd, "@CompanyZip",SqlDbType.NVarChar, 500, ParameterDirection.Input, newTblSettings.CompanyZip);
			AddParameterToSqlCmd(sqlCmd, "@CompanyCity",SqlDbType.NVarChar, 500, ParameterDirection.Input, newTblSettings.CompanyCity);
			AddParameterToSqlCmd(sqlCmd, "@CompanyState",SqlDbType.NVarChar, 500, ParameterDirection.Input, newTblSettings.CompanyState);
			AddParameterToSqlCmd(sqlCmd, "@CompanyCountry",SqlDbType.NVarChar, 500, ParameterDirection.Input, newTblSettings.CompanyCountry);
			AddParameterToSqlCmd(sqlCmd, "@CompanyPhone",SqlDbType.NVarChar, 500, ParameterDirection.Input, newTblSettings.CompanyPhone);
			AddParameterToSqlCmd(sqlCmd, "@CompanyEmail",SqlDbType.NVarChar, 500, ParameterDirection.Input, newTblSettings.CompanyEmail);
			AddParameterToSqlCmd(sqlCmd, "@CompanyFax",SqlDbType.NVarChar, 500, ParameterDirection.Input, newTblSettings.CompanyFax);
			AddParameterToSqlCmd(sqlCmd, "@CustomerPrefix",SqlDbType.NVarChar, 500, ParameterDirection.Input, newTblSettings.CustomerPrefix);
			AddParameterToSqlCmd(sqlCmd, "@OrederPrefix",SqlDbType.NVarChar, 500, ParameterDirection.Input, newTblSettings.OrederPrefix);
			AddParameterToSqlCmd(sqlCmd, "@AdminEmail",SqlDbType.NVarChar, 500, ParameterDirection.Input, newTblSettings.AdminEmail);
			AddParameterToSqlCmd(sqlCmd, "@StockAlertLevel",SqlDbType.Int, 0, ParameterDirection.Input, newTblSettings.StockAlertLevel);
			AddParameterToSqlCmd(sqlCmd, "@MinimumOrder",SqlDbType.Decimal, 9, ParameterDirection.Input, newTblSettings.MinimumOrder);
			AddParameterToSqlCmd(sqlCmd, "@IsGroundShippingFree",SqlDbType.Bit, 0, ParameterDirection.Input, newTblSettings.IsGroundShippingFree);
			AddParameterToSqlCmd(sqlCmd, "@GroundShippingAmount",SqlDbType.Decimal, 9, ParameterDirection.Input, newTblSettings.GroundShippingAmount);
			AddParameterToSqlCmd(sqlCmd, "@HomePageBannerImage",SqlDbType.NVarChar, -1, ParameterDirection.Input, newTblSettings.HomePageBannerImage);
			AddParameterToSqlCmd(sqlCmd, "@HomePageFooterImage",SqlDbType.NVarChar, -1, ParameterDirection.Input, newTblSettings.HomePageFooterImage);
			AddParameterToSqlCmd(sqlCmd, "@HomePageVideoImage",SqlDbType.NVarChar, -1, ParameterDirection.Input, newTblSettings.HomePageVideoImage);
			AddParameterToSqlCmd(sqlCmd, "@FooterImageAnchorUrl",SqlDbType.NVarChar, -1, ParameterDirection.Input, newTblSettings.FooterImageAnchorUrl);
			
			SetCommandType(sqlCmd,CommandType.StoredProcedure,SPR_TBLSETTINGS_UPDATETBLSETTINGS);
            ExecuteScalarCmd(sqlCmd);
			int returnValue = (int)sqlCmd.Parameters["@ReturnValue"].Value;
			return (returnValue == 0 ? false : true);
		}
		#endregion
		
		#region TblSettings Related Collections
		/// <summary>
        /// Creates and returns a strongly typed collection of Employee custom entity. 
        /// The colelction is created through iterating on the IdataReader object which contains Employee information, as a set of records, similar to tabular format.
        /// </summary>
		public static IList  GenerateTblSettingsCollectionFromReader(IDataReader returnData) 
		{
			
			//creating the instance of Employee collection
			List<TblSettings> colTblSettings = new List<TblSettings>();
			
			/************************* Architecure note:**********************************
             * Below code includes the null value functionality to retieve the data which has nill value in database end.
             * Design consideration:
             * Besides general data fields, special care should be taken for primary keys, to assign '0'/defaultvalue, rather passing 'Null' value in constructor parameter.
             * Although we are considering sqldb tyoe data for the current data container, but while retireving data from database end, through datareader object, we need to cast data reader objects using .net primitive data type, 
             * rather using sqldb type to cast, since data reader objects don't support sql db type to be casted.
             *****************************************************************************/

            //Iterating thriugh the data reader, to generate Employee collection.

			//getting the Employee collection by iterating thru the data reader
			while (returnData.Read()) 
			{
				//passing the TblSettings constructor parameters from the current instance of data reader fields.
				TblSettings newTblSettings = new TblSettings
				(
					returnData["SettingsId"]== System.DBNull.Value ? GetSettingsIdMinValue : (Int32 ) returnData["SettingsId"],
					returnData["CompanyName"]== System.DBNull.Value ? string.Empty: (String ) returnData["CompanyName"],
					returnData["CompanyAddress"]== System.DBNull.Value ? string.Empty: (String ) returnData["CompanyAddress"],
					returnData["CompanyZip"]== System.DBNull.Value ? string.Empty: (String ) returnData["CompanyZip"],
					returnData["CompanyCity"]== System.DBNull.Value ? string.Empty: (String ) returnData["CompanyCity"],
					returnData["CompanyState"]== System.DBNull.Value ? string.Empty: (String ) returnData["CompanyState"],
					returnData["CompanyCountry"]== System.DBNull.Value ? string.Empty: (String ) returnData["CompanyCountry"],
					returnData["CompanyPhone"]== System.DBNull.Value ? string.Empty: (String ) returnData["CompanyPhone"],
					returnData["CompanyEmail"]== System.DBNull.Value ? string.Empty: (String ) returnData["CompanyEmail"],
					returnData["CompanyFax"]== System.DBNull.Value ? string.Empty: (String ) returnData["CompanyFax"],
					returnData["CustomerPrefix"]== System.DBNull.Value ? string.Empty: (String ) returnData["CustomerPrefix"],
					returnData["OrederPrefix"]== System.DBNull.Value ? string.Empty: (String ) returnData["OrederPrefix"],
					returnData["AdminEmail"]== System.DBNull.Value ? string.Empty: (String ) returnData["AdminEmail"],
					returnData["StockAlertLevel"]== System.DBNull.Value ? 0: (Int32 ) returnData["StockAlertLevel"],
					returnData["MinimumOrder"]== System.DBNull.Value ? 0: (Decimal ) returnData["MinimumOrder"],
					returnData["IsGroundShippingFree"]== System.DBNull.Value ? false: (Boolean ) returnData["IsGroundShippingFree"],
					returnData["GroundShippingAmount"]== System.DBNull.Value ? 0: (Decimal ) returnData["GroundShippingAmount"],
					returnData["HomePageBannerImage"]== System.DBNull.Value ? string.Empty: (String ) returnData["HomePageBannerImage"],
					returnData["HomePageFooterImage"]== System.DBNull.Value ? string.Empty: (String ) returnData["HomePageFooterImage"],
					returnData["HomePageVideoImage"]== System.DBNull.Value ? string.Empty: (String ) returnData["HomePageVideoImage"],
					returnData["FooterImageAnchorUrl"]== System.DBNull.Value ? string.Empty: (String ) returnData["FooterImageAnchorUrl"]

				);
				//adding the Employee to the collection
				colTblSettings.Add(newTblSettings);
			}
			
			//returns the collection of Companys 
			return (colTblSettings);
		}
		
		#endregion
		#region Constants and Default Values
		
		public static Int32 GetSettingsIdMinValue
		{
			get
			{
				return 0;
			}
		}
		
		//create method related contants
			internal const string SPR_TBLSETTINGS_CREATENEWTBLSETTINGS="spr_TblSettings_CreateNewTblSettings";
			internal const string SPR_TBLSETTINGS_UPDATETBLSETTINGS="spr_TblSettings_UpdateTblSettings";
			internal const string SPR_TBLSETTINGS_DELETETBLSETTINGS="spr_TblSettings_DeleteTblSettings";
			internal const string SPR_TBLSETTINGS_DELETETBLSETTINGSLIST="spr_TblSettings_DeleteTblSettingsList";
			internal const string SPR_TBLSETTINGS_GETTBLSETTINGSBYSETTINGSID="spr_TblSettings_GetTblSettingsBySettingsId";
			internal const string SPR_TBLSETTINGS_GETALLTBLSETTINGS="spr_TblSettings_GetAllTblSettings";
			internal const string SPR_TBLSETTINGS_GETALLTBLSETTINGSPAGED="spr_TblSettings_GetAllTblSettingsPaged";
			internal const string SPR_TBLSETTINGS_GETALLTBLSETTINGSPAGEDCOUNT="spr_TblSettings_GetAllTblSettingsPagedCount";
		
		#endregion
	}
}	
